//
//  MASExampleMulLabelAutoSizeView.m
//  MasonryExample
//
//  Created by 山刘 on 2020/6/10.
//  Copyright © 2020 山刘. All rights reserved.
//

#import "MASExampleMulLabelAutoSizeView.h"

@interface MASExampleMulLabelAutoSizeView()
@property (nonatomic, strong) UILabel *label;
@end

@implementation MASExampleMulLabelAutoSizeView

- (id)init {
    self = [super init];
    if (!self) return nil;
    
    self.label = [LayoutUtils fixedLabelWithText:@"最近是用Masonry自动布局UILabel的时候，;这些东西之后，label还是没有换行。最近是用Masonry自动布局UILabel的时候，"];
    self.label.textAlignment = NSTextAlignmentLeft;
    [self addSubview:self.label];
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(100);
        make.left.mas_equalTo(15);
    }];
    
    UIButton *button = [LayoutUtils createButtonWithTitle:@"添加文字" target:self selector:@selector(clickButton:)];
    [self addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.label.mas_bottom).mas_offset(20);
        make.centerX.mas_equalTo(self);
        make.height.mas_equalTo(50);
        make.width.mas_lessThanOrEqualTo(300);
    }];
    
    return self;
}

-(void)clickButton:(UIButton*)sender{
    self.label.text = [self.label.text stringByAppendingString:@"Masonry自动布局YYLabel"];
}

-(void)layoutSubviews{
    [super layoutSubviews];
    self.label.preferredMaxLayoutWidth = CGRectGetWidth(self.frame) - 30;
}
@end
